<template>
    <div>
        <van-nav-bar class="bj" title="注册/登录" left-arrow/>
        <div>
            <van-cell-group>
                <van-field v-model="tel" left-icon="shouji" placeholder="请输入手机号">
                    <van-icon class="iconfont" class-prefix="icon" slot="left-icon" name="shouji"></van-icon>
                </van-field>            
            </van-cell-group>
            <van-cell-group>
                <van-field v-model="message" left-icon="mima" placeholder="请输入密码">
                    <van-icon class="iconfont" class-prefix="icon" slot="left-icon" name="mima"></van-icon>
                </van-field>
            </van-cell-group>
            <div class="an">
                <van-button class="tj" type="primary" @click="pad">登录</van-button>
                <p @click="zhuan">还没账号？立即注册</p>
            </div>
        </div>
    </div>
</template>
<script>
import { setToken,getpre } from '@/until/auth'
export default{
    data(){
        return{
            tel:'',
            message:'',
        }
    },
    methods:{
        
        zhuan(){
            this.$router.push('/login')
        },
        pad(){
            this.$http.post('/user/login',{
                username:this.tel,
                password:this.message
            })
            .then((res)=>{
                console.log(res)
                setToken(res.token)
                this.getuserInfo(res.token)
            })
            .then((error)=>{
                console.log(error)
            })
        },
        getuserInfo(token){
            this.$http.post('/user/getuserInfo',{
                token:token
            })
            .then((res)=>{
                console.log(res)
                localStorage.setItem('uid',res.uid)
                let userInfo = JSON.stringify(res.userInfo)
                localStorage.setItem('userInfo',userInfo)
                this.$router.push(getpre())
            })
        }
    } 
}
</script>
<style>
.bj{
    width: 100%;
    height:46px;
    background-color: rgb(7,193,96);
}
.van-nav-bar .van-icon{
    color: #fff;
}
.an{
    height: 45px;
    width: 85%;
    display:block;
    margin:0 auto;
    background-color: rgb(7,193,96);
    margin-top: 30px;
}
.tj{
    height: 40px;
    display: block;
    margin: 0 auto;
    font-size: 16px;
}
.an p{
    color: #a59999;
    float: right;
    font-size: 16px;
    margin-top: 30px;
}
</style>